using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using SJXmlP.XMLClasses;
using Spacejock;
using System;
using System.Collections;
using yW5Lib;

namespace yWriter6
{
	[StandardModule]
	internal sealed class modExportDescriptions
	{
		public static void ExportDescriptionsByChapter(ref clsProject cProject)
		{
			//Discarded unreachable code: IL_0224, IL_023b, IL_0246, IL_0256, IL_02e4, IL_02e6, IL_02fa, IL_031c
			int num = default(int);
			int num3 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				if (cProject.ChapterCount != 0)
				{
					num2 = 4;
					clsCollection<int> clsCollection = new clsCollection<int>();
					num2 = 5;
					frmPickChapters frmPickChapters = new frmPickChapters(ref cProject);
					num2 = 6;
					frmPickChapters.ShowDialog();
					num2 = 7;
					if (!frmPickChapters.Cancelled)
					{
						num2 = 9;
						clsCollection = frmPickChapters.PickedIDs;
						num2 = 10;
						clsShared.cSubs.BusyMouse();
						num2 = 11;
						string text = cProject.ProjectPath() + "Auto_Descriptions.txt";
						num2 = 12;
						clsShared.cFile.SaveTextFile(text, cProject.Title + "\r\n\r\n");
						num2 = 13;
						IEnumerator enumerator = clsCollection.GetEnumerator();
						int value = default(int);
						while (enumerator.MoveNext())
						{
							int iD = Conversions.ToInteger(enumerator.Current);
							num2 = 14;
							clsChapter clsChapter = cProject.get_ChapterByID(iD);
							num2 = 15;
							if (frmPickChapters.WithUnused | !clsChapter.Unused)
							{
								num2 = 16;
								string title = clsChapter.Title;
								num2 = 17;
								clsFile cFile = clsShared.cFile;
								string TextString = title + "\r\n";
								cFile.AppendToTextFile(text, ref TextString);
								num2 = 18;
								int sceneCount = clsChapter.SceneCount;
								for (int i = 1; i <= sceneCount; i++)
								{
									num2 = 19;
									clsScene clsScene = cProject.get_SceneByChID(clsChapter.ID, i);
									num2 = 20;
									if (frmPickChapters.WithUnused | !clsScene.Unused)
									{
										num2 = 21;
										title = " " + Conversions.ToString(value) + "." + Conversions.ToString(i) + " " + clsScene.Title;
										num2 = 22;
										clsShared.cText.RemoveCRLFFromEnd(ref title);
										num2 = 23;
										clsFile cFile2 = clsShared.cFile;
										TextString = title + "\r\n";
										cFile2.AppendToTextFile(text, ref TextString);
									}
									num2 = 24;
								}
							}
							num2 = 25;
						}
						num2 = 26;
						if (enumerator is IDisposable)
						{
							(enumerator as IDisposable).Dispose();
						}
						num2 = 27;
						clsShared.cSubs.NormalMouse();
						num2 = 28;
						clsShared.cLang.TransMsgBox("Your summary was saved to @1@", MsgBoxStyle.OkOnly, "", text);
					}
				}
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num3 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_031a: Could not find block for branch target IL_02e6*/;
			}
			if (num3 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
